import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Set;

/**
 * @author LKQ
 * @date 2022/2/15 15:40
 * @description
 */
public class Solution2 {
    Deque<TreeNode> deque = new ArrayDeque<>();
    Set<Integer> set = new HashSet<>();

    public int numColor(TreeNode root) {
        if (root != null) {
            deque.add(root);
        }
        while (!deque.isEmpty()) {
            TreeNode treeNode = deque.removeFirst();
            set.add(treeNode.val);
            if (treeNode.left != null) {
                deque.addFirst(treeNode.left);
            }
            if (treeNode.right != null) {
                deque.addFirst(treeNode.right);
            }
        }
        return set.size();

    }
}
